import ModuleTemplate from '@/utils/ModuleTemplate';
import appService from '@/utils/appService';
import systemConfig from '@/utils/config';
/** modules名称空间 */
export const namespace = 'payOrder';
const model = {
    name: namespace,
    /** 基本属性 */
    state: {
        /** 分页数据查询条件 */
        query: {
            currentPage: 1,
            pageSize: 10
        }
    },
    /** 从基本数据派生的数据,getters接收state作为其第一个参数，
     * 接受其他 getters 作为第二个参数，如不需要，第二个参数可以省略
     */
    getters: {},
    /** 执行同步操作，包含用于直接修改state的函数 */
    mutations: {
        /** 如果 url 没有带参数就重置一下 query 的参数 **/
        reviseQuery(store) {
            store.query = {
                currentPage: 1,
                pageSize: 10
            };
        }
    },
    /** 异步操作，可调用同步操作函数 */
    actions: {
        getSearchKey(store, payload) {
            return new Promise((resolve, reject) => {
                appService.getRequest(`${config.dataSource}/admin/property/dictionary`, payload).then(result => {
                    if (result && result.status === 200) {
                        resolve(result);
                    } else {
                        reject(Error);
                    }
                });
            });
        },
        getFlowDetail(store, payload) {
            return new Promise((resolve, reject) => {
                appService.getRequest(`${config.dataSource}/admin/flowDetail/findSettleByFlowId/${payload.flowId}`, payload).then(result => {
                    if (result && result.status === 200) {
                        resolve(result);
                    } else {
                        reject(Error);
                    }
                });
            });
        },
        // 导出excel
        exportExcel(store, payload) {
          return new Promise((resolve, reject) => {
            appService.postRequest(`${config.dataSource}/admin/flow/exportList`, payload, { responseType: 'arraybuffer' }).then((result) => {
              if (result && result.status === 200) {
                resolve(result);
              } else {
                reject(Error);
              }
            });
          });
        }
    },
    /** 子模块 */
    modules: {}
};
const config = {
    /** 数据源，对应后端controller类的请求映射,
     * 如果不指定则默认和name一样
     */
    // dataSource: systemConfig.tradeInvoicePath + '/admin/paypayer',
    dataSource: systemConfig.serverProxy + '/trade-payment',
    invoiceServer: true,
    /** query函数调用的后端controller方法的请求映射 */
    queryMethod: '/admin/flow/findPageList',
    updateMethod: null,
    deleteMethod: null,
    saveMethod: null,
    getDetailMethod: '/admin/flow/'
};
const moduleTemplate = new ModuleTemplate(model, config);
export const module = moduleTemplate.createModel();
